package mirrormonkey.util.serializer;

import java.io.IOException;
import java.nio.ByteBuffer;

import com.jme3.math.ColorRGBA;
import com.jme3.network.serializing.Serializer;

/**
 * Serializes and deserializes <tt>ColorRGBAs</tt> by reading or writing their
 * R, G, B, and A values.
 * 
 * @author Philipp Christian Loewner
 * 
 */
public class ColorRGBASerializer extends Serializer {

	@Override
	@SuppressWarnings("unchecked")
	public <T> T readObject(ByteBuffer data, Class<T> c) throws IOException {
		return (T) new ColorRGBA(data.getFloat(), data.getFloat(),
				data.getFloat(), data.getFloat());
	}

	@Override
	public void writeObject(ByteBuffer buffer, Object object)
			throws IOException {
		ColorRGBA color = (ColorRGBA) object;
		buffer.putFloat(color.r);
		buffer.putFloat(color.g);
		buffer.putFloat(color.b);
		buffer.putFloat(color.a);
	}

}
